package com.eleadmin.store.service.impl;

import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.common.core.web.JsonResult;
import com.eleadmin.common.system.entity.User;
//import com.eleadmin.store.mapper.ProductStorageMapper;
import com.eleadmin.store.entity.ProductStorage;
import com.eleadmin.store.result.PriceResult;
import com.eleadmin.store.service.ProductStorageService;
import org.springframework.stereotype.Service;
import com.eleadmin.store.biz.ProductStorageBiz;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 库存服务实现类
 *
 * @author : Doman
 * @version ：1.0
 * @date : 2024-02-13 18:44:18
 */
@Service
public class ProductStorageServiceImpl /*extends ServiceImpl<ProductStorageMapper, ProductStorage> */ implements ProductStorageService {

    @Autowired
    private ProductStorageBiz productStorageBiz;

    @Override
    public JsonResult list(PageResult2<T> page, ProductStorage productStorage, User loginUser) throws Exception {
        JsonResult jr = productStorageBiz.list(page, productStorage, loginUser);
        PriceResult priceResultp = productStorageBiz.storageNums(productStorage, loginUser);
        jr.put("liTotalWeightTotal", priceResultp.getLiTotalWeight());
        return jr;
    }

    @Override
    public JsonResult pageNoStorageNums(PageResult2<T> page, ProductStorage productStorage, User loginUser) throws Exception {
        JsonResult jr = productStorageBiz.list(page, productStorage, loginUser);
        return jr;
    }

    @Override
    public JsonResult storageNums(ProductStorage productStorage, User loginUser) throws Exception {
        return JsonResult.ok().setData(productStorageBiz.storageNums(productStorage, loginUser));
    }

    @Override
    public JsonResult list(ProductStorage productStorage, User loginUser) {
        return JsonResult.ok().setData(productStorageBiz.list(productStorage, loginUser));
    }

    @Override
    public JsonResult listSel(ProductStorage productStorage, User loginUser) {
        return JsonResult.ok().setData(productStorageBiz.listSel(productStorage, loginUser));
    }

    @Override
    public JsonResult productStorageNum(ProductStorage productStorage, User loginUser) {
        try {
            return JsonResult.ok().setData(productStorageBiz.productStorageNum(productStorage, loginUser));
        } catch (Exception e) {
            return JsonResult.ok().setData(0);
        }
    }

    @Override
    public JsonResult getById(String id) {
        return JsonResult.ok().setData(productStorageBiz.getById(id));
    }

    @Transactional
    @Override
    public JsonResult save(ProductStorage productStorage, User loginUser) {
        if (productStorageBiz.save(productStorage, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(ProductStorage productStorage, User loginUser) {
        if (productStorageBiz.update(productStorage, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(String id, User loginUser) {
        if (productStorageBiz.remove(id, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
